<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改班级')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-gradeclass-edit" th:object="${manageGradeClass}">
            <input name="id" th:field="*{id}" type="hidden">
            <input id="leaderTableId" name="leaderId" type="hidden" th:field="*{leaderId}" />
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">入学年份：</label>
                <div class="col-sm-8">
                    <select id="gradeYear" name="gradeYear" class="form-control m-b" required>
                        <option value="2019" th:field="*{gradeYear}">2019</option>
                        <option value="2020" th:field="*{gradeYear}">2020</option>
                        <option value="2021" th:field="*{gradeYear}">2021</option>
                        <option value="2022" th:field="*{gradeYear}">2022</option>
                        <option value="2023" th:field="*{gradeYear}">2023</option>
                        <option value="2024" th:field="*{gradeYear}">2024</option>
                        <option value="2025" th:field="*{gradeYear}">2025</option>
                        <option value="2026" th:field="*{gradeYear}">2026</option>
                        <option value="2027" th:field="*{gradeYear}">2027</option>
                        <option value="2028" th:field="*{gradeYear}">2028</option>
                        <option value="2029" th:field="*{gradeYear}">2029</option>
                        <option value="2030" th:field="*{gradeYear}">2030</option>
                        <option value="2031" th:field="*{gradeYear}">2031</option>
                        <option value="2032" th:field="*{gradeYear}">2032</option>
                        <option value="2033" th:field="*{gradeYear}">2033</option>
                        <option value="2034" th:field="*{gradeYear}">2034</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">年级：</label>
                <div class="col-sm-8">
                    <input name="gradeNum" th:field="*{gradeNum}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">班级：</label>
                <div class="col-sm-8">
                    <input name="classNum" th:field="*{classNum}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">班级code标识：</label>
                <div class="col-sm-8">
                    <input name="classCode" th:field="*{classCode}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">班级状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box">
                        <input type="radio" name="status" id="status-1" value="1" th:field="*{status}">
                        <label for="status-1">正常</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" name="status" id="status-2" value="0" th:field="*{status}">
                        <label for="status-2">已毕业</label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">班主任ID：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input class="form-control" type="text" onclick="selectLeaderWindow()" id="leaderTableName" readonly="true" th:value="${manageGradeClass.leader == null ? '无' : manageGradeClass.leader.userName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "aftserv/gradeclass";
        $("#form-gradeclass-edit").validate({
            onkeyup: false,
            rules:{
                classCode:{
                    maxlength:60,
                    remote: {
                        url: prefix + "/checkClassCodeUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "id": function() {
                                return $("input[name='id']").val();
                            },
                            "classCode" : function() {
                                return $.common.trim($("#classCode").val());
                            }
                        }
                    }
                },
                gradeNum:{
                    maxlength:2,
                    digits:true
                },
                classNum:{
                    maxlength:2,
                    digits:true
                },
            },
            messages: {
                "classCode": {
                    remote: "班级标识编码已存在！"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-gradeclass-edit').serialize());
            }
        }

        /*行政组管理-新增-选择组长列表*/
        function selectLeaderWindow() {
            var treeId = $("#leaderTableId").val();
            var leaderId = treeId > 0 ? treeId : 1;
            var options = {
                title: '班主任选择',
                width: "800",
                url: ctx + "system/user/selectUserList/"+leaderId,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero) {
            var body = $.modal.getChildFrame(index);
            $("#leaderTableId").val(body.find('#tableId').val());
            $("#leaderTableName").val(body.find('#tableName').val());
            $.modal.close(index);
        }
    </script>
</body>
</html>